<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>角色添加</title>
<meta name="content-type" content="text/html; charset=UTF-8">
<div th:replace="/pub.html"></div>
<script type="text/javascript">
var resourceTree;
$(function(){
	resourceTree = $('#resourceTree').tree({
		method : 'get',
		url : '/perm/menu/tree',
		parentField : 'pid',
		//lines : true,
		//cascadeCheck : false,
		checkbox : true,
		onCheck : function(node, checked) {
			//var nodes = resourceTree.tree('getChecked');
			//var nodes = resourceTree.tree('getChecked', ['checked','indeterminate']);
			var nodes = resourceTree.tree('getChecked', 'checked');
			var nodes2 = resourceTree.tree('getChecked', 'indeterminate');
            var s1 = '';
            for(var i=0; i<nodes.length; i++){
                if (s1 != '') s1 += ',';
                s1 += nodes[i].id;
            }
            var s2 = '';
            for(var i=0; i<nodes2.length; i++){
                if (s2 != '') s2 += ',';
                s2 += nodes2[i].id;
            }
            $("#moduleids").val(s1);
            $("#parentModuleid").val(s2);
            //console.info(s1);
            //console.info(nodes2);
		},
		onLoadSuccess : function(node, data) {
			var ids = $.stringToList($("#moduleids").val());
			if (ids.length > 0) {
				for ( var i = 0; i < ids.length; i++) {
					if (resourceTree.tree('find', ids[i])) {
						resourceTree.tree('check', resourceTree.tree('find', ids[i]).target);
					}
				}
			}
		}
	});
});
var roleadd_submitForm = function(dialog, role_treeGrid, p) {
	if ($('#role_addForm').form('validate')) {
		$.post('/perm/role/add', $("#role_addForm").serialize(), function(j) {
			if (j.success) {
				role_treeGrid.datagrid('reload');
				dialog.dialog('destroy');
			}
			p.messager.show({
				title : '提示',
				msg : j.msg,
				timeout : 5000,
				showType : 'slide'
			});
		}, 'json').error(function() {
			$.messager.show({
				title : '提示',
				msg : '你的权限不够',
				timeout : 5000,
				showType : 'slide'
			});
		});
	}
};

function AllChecked(a){
	$("#ch"+a).children().each(function(){
		if(this.checked==true){
			this.checked=false;
		}else{
			this.checked=true;
		}
	});
}
</script>
</head>

<body>
	<form id="role_addForm" method="post">
	<input type="hidden" id="roleId" name="id" th:field="${role.id}"/>
	<input type="hidden" id="parentModuleid" name="parentPermissionIds"/>
	<input type="hidden" name="permissionIds" id="moduleids" th:field="${role.permissionIds}"/>
		<table style="width: 100%;" class="table table-hover table-condensed">
			<tr>
				<th>角色名称</th>
				<td><input id="roleName" name="name" th:field="${role.name}" class="easyui-validatebox"
					data-options="required:true,missingMessage:'角色名称必填'" /></td>
			</tr>
			<!-- <tr>
				<th>备注</th>
				<td><input name="remark" value="${role.remark}"/></td>
			</tr> -->
		</table>
	
	<fieldset>
	    <legend>权限选择</legend>
	    <ul id="resourceTree"></ul>
	</fieldset>
	
	</form>
</body>
</html>